package top.kaoshanji.p1ch04a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.DateFormat;
import java.text.ParsePosition;
import java.util.Date;

/**
 * 代码清单 p1ch04a-11：设置解析时的起始位置的示例
 * author kaoshanji
 * ^_^
 * create time 2025/1/15 19:28
 */
public class DateFormatExample02 {

    private static final Logger logger = LogManager.getLogger(DateFormatExample02.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p1ch04a-11：设置解析时的起始位置的示例...");

        DateFormat format = DateFormat.getDateInstance(DateFormat.FULL);
        Date date = new Date();
        String dateStr = format.format(date);
        String prefix = "== START ==";
        String toParse = prefix + dateStr + "== END ==";
        ParsePosition position = new ParsePosition(prefix.length());
        Date d = format.parse(toParse, position);
        int index = position.getIndex();

        logger.info("...index:{}...", index);

    }

}
